package com.zhu.test;


/*Java运行时多态性：继承和接口的实现
* 一、通过继承中超类对象引用变量引用子类对象来实现
* 二、通过接口类型变量引用实现接口的类的对象来实现
* */
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zhujiabao
 * @Date: 2022/02/17/11:14
 * @Description:
 */
public class polymorphism {
    public static void main(String[] args){
        superA a;

        subB  b = new subB();
//        subC  c = new subC();

        a=b;
        a.fun();
        a.staticFun();

//        a=c;
//        a.fun();

    }
}


//定义超类superA
class superA{
    int i = 100;
    void fun(){
        System.out.println("This is subA");
    }

    static void staticFun(){
        System.out.println("this is staticAAA");
    }
}

//定义接口InterA
interface interA{
    void fun();
}

//定义superA的子类subB
class subB extends superA{
    int m = 1;
    public void fun(){
        System.out.println("This is subB");
    }
    static void staticFun(){
        System.out.println("this is staticBBB");
    }
}

//定义superA的子类subC
class subC implements interA{
    int n = 1;
    public void fun(){
        System.out.println("This is subC");
    }
}